﻿CREATE proc [dbo].[proc_Customer_PiZhu_Create] --创建客户批注
(
   @CustomerId uniqueidentifier,
  @Pizhu nvarchar(500),
  @CreateUserId nvarchar(50),
  @CreateTime datetime
 )
 as
 begin
 if not exists (select Id from Customer_PiZhu where CustomerId=@CustomerId)
  if(@Pizhu='')
  insert into  Customer_PiZhu (CustomerId,Pizhu,CreateuserId,Createtime,CusState) values (@CustomerId,@Pizhu,@CreateUserId,@CreateTime,0)
  else
    insert into  Customer_PiZhu (CustomerId,Pizhu,CreateuserId,Createtime,CusState) values (@CustomerId,@Pizhu,@CreateUserId,@CreateTime,1)

  
 else
 if(@Pizhu='')
 
 update Customer_PiZhu  set Pizhu=@Pizhu,CreateUserId=@CreateUserId,CreateTime=@CreateTime,CusState=0 where CustomerId=@CustomerId
 else
 
 update Customer_PiZhu  set Pizhu=@Pizhu,CreateUserId=@CreateUserId,CreateTime=@CreateTime,CusState=1 where CustomerId=@CustomerId

 end
 

--create table Customer_PiZhu
--( Id int primary key identity(1,1) not null,
--  CustomerId uniqueidentifier,
--  Pizhu nvarchar(max),
--  CreateUserId nvarchar(50),
--  CreateTime datetime
-- )

--ALTER TABLE Customer_PiZhu ADD [CusState] int NULL